# ================== 导入包 ==================
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).parent.parent))  # 将项目根目录加入Python路径
from config import Config
from sentence_transformers import SentenceTransformer
from langchain_openai import OpenAI




# ================== 初始化模型 ==================
def init_models():
    """初始化模型并验证"""
    # Embedding模型
    # embed_model = SentenceTransformer(
    #     # model_name=Config.EMBED_MODEL_PATH,
    #     model_name_or_path= r'E:\work\2025_fufeng\nl2\embedding_model\sentence-transformers\msmarco-MiniLM-L-6-v3'
    # )
    model_path = r'E:\work\2025_fufeng\nl2\embedding_model\sentence-transformers\msmarco-MiniLM-L-6-v3'

    # 加载模型
    try:
        embed_model = SentenceTransformer(model_path)
        print("模型加载成功")
    except Exception as e:
        print(f"模型加载失败：{e}")
        exit()

    # 生成嵌入并验证
    try:
        embedding = embed_model.encode("hi this is harrison")
        print(f"Embedding维度验证：{len(embedding)}")
    except Exception as e:
        print(f"生成嵌入失败：{e}")

    # LLM模型
    llm = OpenAI(
    model="deepseek-r1",
    api_base=Config.LLM_API_BASE_URL,
    api_key="fake",
    temperature=0,
    max_retries=2,
    context_window=4096,
    is_chat_model=True,
    is_function_calling_model=False,
    )
    
    # rerank模型
    reranker = ''

    
    # return embed_model, llm, reranker  # 返回重排序器'


# ================== 向量存储 ==================


if __name__ =='__main':
    init_models()